import pygame

# file: not none, exsits
# colorkey: 0-255
def load_image(file, colorkey = None):
    image = pygame.image.load(file).convert()
    if colorkey: image.set_colorkey(colorkey, pygame.RLEACCEL)
    return image

# file: not none, exsits
# (sx, sy): not none, width > sx > 0, sy same
# colorkey: 0-255
def load_frame(file, (sx, sy), colorkey = None):
    image = pygame.image.load(file).convert()
    if colorkey is not None: image.set_colorkey(colorkey, pygame.RLEACCEL)
    allrect = image.get_rect()
    width = (allrect.width) // sx
    height = (allrect.height) // sy
    frame = []
    for x in range(0, allrect.width, width):
        for y in range(0, allrect.height, height):
            sub = pygame.Surface((width, height))
            sub.blit(image, (0, 0), (x, y, width, height))
            if colorkey: sub.set_colorkey(colorkey, pygame.RLEACCEL)
            frame.append(sub)
    return tuple(frame)

# shape: not none
# (width, height): > 0
# color: not none, 0-255
def load_shape(shape, (width, height), color):
    if shape == 'rect':
        image = pygame.Surface((width, height))
        pygame.draw.rect(image, color, pygame.Rect(0, 0, width, height))
    return image








